package com.epam.concurrency.circbuffer;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * Consumer (Reader) for Circular Buffer
 * @author Yuriy Miedviediev
 * @version 1.0 Build 15.05.2014
 */
public class Consumer implements Runnable {

    private final CircularBuffer cb;

    private static final Logger LOGGER = LoggerFactory.getLogger(Consumer.class);
    private static final int SLEEPTIME = 400;

    public Consumer(CircularBuffer cb) {
        this.cb = cb;
    }

    @Override
    public void run() {
        while(true) {

            LOGGER.info(Integer.toString(cb.poll()));

            try {
                Thread.sleep(SLEEPTIME);
            } catch (InterruptedException e) {
                LOGGER.error(e.getMessage());
            }
        }
    }
}